package hot100;

public class Solution121 {

    public int maxProfit(int[] prices) {
        int last0 = 0;
        int maxProfit = 0;
        for (int i = 1; i < prices.length; i++) {
            int current0 = Math.max(last0 - prices[i - 1] + prices[i], 0);
            maxProfit = Math.max(current0, maxProfit);
            last0 = current0;
        }
        return maxProfit;
    }

    public static void main(String[] args) {
        Solution121 solution124 = new Solution121();
        System.out.println(solution124.maxProfit(new int[]{7,1,5,3,6,4}));
    }
}
